package com.bwjf.dzfp.entity;

import com.alibaba.fastjson.JSONObject;

/**
 * 带参数的结果
 * 
 * @author llq
 * 
 */
public class ResultData<T> {
	private boolean success = false;
	private String msg;
	private T data;

	/**
	 * 结果数据 返回参数，默认成功
	 * 
	 * @param data
	 */
	public ResultData(T data) {
		this.success = true;
		this.msg = "成功";
		this.data = data;
	}

	/**
	 * 结果数据 返回参数，默认成功
	 * 
	 * @param data
	 */
	public ResultData(boolean success, String errMsg) {
		this.success = success;
		this.msg = errMsg;
	}

	/**
	 * 结果数据 返回参数，默认成功
	 * 
	 * @param data
	 */
	public ResultData(boolean success, String successMsg, String errorMsg,
			T data) {
		this.success = success;
		if (success) {
			this.data = data;
			this.msg = successMsg;
		} else {
			this.msg = errorMsg;
		}
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String toJSONString() {
		return JSONObject.toJSONString(this);
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
}
